PSPad editor script interface description

Note!
Don’t place any non script files direct into script language subdirectories !
All files e.g. in VBScript subrirectory are consider as script and non script file causes compilation error.

modules library

You can write own library and share function from library in other scripts. Unique module_name is identifier.
To call function from other module, place module name before function name:
myLibrary.someFunction()

global functions/subroutines

addMenuItem(caption: string; submenu: string; procedure: string)
creates menu item in PSPad main menu. if you don't want submenu, send empty string as parameter
Its contained in script Init subroutine and works only during Init phase. All other calling is ignored.

echo(text: string)
information box with text and button OK
sleep(ms: integer)
stops script execution for number of miliseconds
inputText(label [, default_value [, cancel_value]]: string): string
input text dialog. Cancel_value is returned after press Cancel button.

setClipboardText(text: string)
stores text into clipboard
getClipboardText(): string
returns text from clipboad

runAction(ActionName: string)
allows to run any PSPad editor action. List of actions follows.

logClear
clears whole LOG window content
logAddLine(test: string)
adds new line into LOG
logGetLine(index: integer): string
returns line from LOG, identified by index parameter (numbered from 0)
logSetLine(index: integer, test: string)
sets log line, identified by index
logLinesCount(): Integer
returns current number of LOG window lines

pspadVersion(): string
returns PSPad version
moduleExists(name: string):boolean
returns True if script module exists
moduleVersion(name: string):string
returns version of module, if module doesn't exists, returns empty string
moduleFileName(name: string):string
returns file name of module, if module doesn't exists, returns empty string.
modulePath():string
returns module file path include last backslash

closeEditorByTitle(file_name: string): boolean
closes editor by filename
closeEditorByIndex(index: integer): boolean
closes editor by index
closeAllEditors
closes all editor windows
editorsCount: integer
vrací počet otevřených editorů

projectFilesCount: integer
vrací počet souborů v projektu, v cyklu pouzivat od 0 do projectFilesCount-1
projectFiles(index: integer): string
vrací jméno souboru z projektu podle indexu, pokud soubor neexistuje, vrací prázdný řetězec
projectFileName: string
vrací jméno souboru projektu
projectSave
uloží projekt

ftpConnect(connection_name: string): boolean
connect to in PSPad defined FTP connection
ftpDisconnect
disconnect FTP server
ftpCommand(command: string): string
send command to FTP server, e.g. "CWD \public\www". Function returns FTP server return stringserveru
ftpDownloadFile(ftp_filename, local_filename): boolean
download file from ftp and stored it as local file
ftpUploadFile(local_filename, ftp_filename): boolean
uploads local file to current FTP directory

newEditor(): object
creates new object for editor handling

editor object function

assignEditorByName(file_name: string): boolean
assign editor window to object by file name
assignEditorByIndex(index: integer): boolean
assign editor window to object by editor index
assignActiveEditor(): boolean
assign active editor window into object and show it
assignLog(): boolean
this function is obsolete now. Is replaced with logXXXXX() functions. Now returns always 0, in the past returns always 1
newFile([file_name: string]): boolean
creates new file in PSPad. File name is optional
openFile(file_name: string): boolean
opens existing file in new editor window
saveFile(): boolean
saves file
saveFileAs(file_name: string): boolean
saves file as
reloadFile(): boolean
reload file
closeFile(): boolean
closes file
text(string):string
replaces/returns all editor text
selText(string): string
replaces/returns selected text from editor
lineText(string): string
replaces/returns content of active line
linesCount(): integer
returns editor lines count
appendText(string): boolean
appends text to editor end
fileName(string): string
sets/returns editor file name
command(editor_command: string): boolean
runs editor command processor command
setCaretPos(x: integer; y: integer): boolean
sets editor caret position. -1 in  parameter mean no change coordinate
caretX(integer): integer
sets/returns editor CaretX position
caretY(integer): integer
sets/returns editor CaretY position
setBlockBegin(x: integer; y: integer): boolean
sets start of the block
setBlockEnd(x: integer; y: integer): boolean
sets end of the block
selectionMode(s: string)
sets selection mode. C: column, N: normal, L: line selection
blockBeginX: integer
returns block start column
blockBeginY: integer
returns block start line
blockEndX: integer
returns block end column
blockEndX: integer
returns block end line
selStart(integer): integer
returns/sets block start
selLength(integer): integer
returns/sets block length

editor commands list

ecLeft            move cursor left one char
ecRight           move cursor right one char
ecUp              move cursor up one line
ecDown            move cursor down one line
ecWordLeft        move cursor left one word
ecWordRight       move cursor right one word
ecLineStart       move cursor to beginning of line
ecLineEnd         move cursor to end of line
ecPageUp          move cursor up one page
ecPageDown        move cursor down one page
ecPageLeft        move cursor right one page
ecPageRight       move cursor left one page
ecPageTop         move cursor to top of page
ecPageBottom      move cursor to bottom of page
ecEditorTop       move cursor to absolute beginning
ecEditorBottom    move cursor to absolute end
ecNextLineStart   move cursor to next line begining
                   
ecSelLeft         ecLeft + ecSelection;
ecSelRight        ecRight + ecSelection;
ecSelUp           ecUp + ecSelection;
ecSelDown         ecDown + ecSelection;
ecSelWordLeft     ecWordLeft + ecSelection;
ecSelWordRight    ecWordRight + ecSelection;
ecSelLineStart    ecLineStart + ecSelection;
ecSelLineEnd      ecLineEnd + ecSelection;
ecSelPageUp       ecPageUp + ecSelection;
ecSelPageDown     ecPageDown + ecSelection;
ecSelPageLeft     ecPageLeft + ecSelection;
ecSelPageRight    ecPageRight + ecSelection;
ecSelPageTop      ecPageTop + ecSelection;
ecSelPageBottom   ecPageBottom + ecSelection;
ecSelEditorTop    ecEditorTop + ecSelection;
ecSelEditorBottom ecEditorBottom + ecSelection;
                    
ecScrollUp        scroll up one line leaving cursor position unchanged.
ecScrollDown      scroll down one line leaving cursor position unchanged.
ecScrollLeft      scroll left one char leaving cursor position unchanged.
ecScrollRight     scroll right one char leaving cursor position unchanged.
                    
ecInsertMode      set insert mode
ecOverwriteMode   set overwrite mode
ecToggleMode      toggle ins/ovr mode
                    
ecNormalSelect    normal selection mode
ecColumnSelect    column selection mode
ecLineSelect      line selection mode
                    
ecMatchBracket    go to matching bracket
                    
ecGotoMarker0     goto marker
...
ecGotoMarker9     goto marker
ecSetMarker0      set marker
...
ecSetMarker9      set marker
                    
ecDeleteLastChar  delete last char (i.e. backspace key)
ecDeleteChar      delete char at cursor (i.e. delete key)
ecDeleteWord      delete from cursor to end of word
ecDeleteLastWord  delete from cursor to start of word
ecDeleteBOL       delete from cursor to beginning of line
ecDeleteEOL       delete from cursor to end of line
ecDeleteLine      delete current line
ecClearAll        delete everything
ecLineBreak       break line at current position, move caret to new line
ecInsertLine      break line at current position, leave caret
                    
ecUndo            perform undo if available
ecRedo            perform redo if available
ecCut             cut selection to clipboard
ecPaste           paste clipboard to current position
ecSelectAll       select entire content of editor, cursor to end
ecCopy            copy selection to clipboard
                    
ecBlockIndent     indent selection
ecBlockUnindent   unindent selection
ecTab             tab key
ecShiftTab        shift+Tab key
                    
ecUpperCase       apply to the current or previous word
ecLowerCase         
ecToggleCase        
ecTitleCase         
ecUpperCaseBlock  apply to current selection, or current char if no selection
ecLowerCaseBlock    
ecToggleCaseBlock   

PSPad actions list

aAddDiacritic	Add accent marks (dictionary is required)
aAddFile	Add current file to project
aAddFilesToFolder	Add Files to project - dialog
aAddFolder	New folder to project
aAllToASCII	Remove Accent from chars
aAutoCompl	Auto completion
aAutoRefresh	Set Autorefresh flag for window
aBlockAlign	Align selection to block
aBlockCenter	Justify block to the center
aBlockLeft	Justify block to the left
aBlockRight	Justify block to the right
aCapitalize	Capitalize block
aClose	Close window
aCloseAll	Close All
aCodeExplorer	Code Explorer window
aCodeFormat	Code Case Change dialog
aColorSelect	Color Selector window
aComment	Add/Remove Comment
aCompile	Compile
aCopy	Copy
aCopyLine	Copy Line
aCSSToInLine	Reformat into Inline CSS
aCSSToStructure	Reformat into Structured CSS
aCSVImport	Import from CSV dialog
aCut	Cut
aDateTime	Insert Date Time
aDateTimeDialog	Date Time Dialog
aDecToHex	Decimal to Hexadecimal selection
aDelete	Delete
aDelFolder	Remove Folder from project
aDelMark	Delete Bookmark
aDelMarks	Delete all Bookmarks
aDiffSame	Text Diff with File Contents on Disk
aExit	Exit
aExpClipHTML	Export to Clipboard as HTML
aExpClipRTF	Export to Clipboard as RTF
aExpClipTeX	Export to Clipboard as &TeX
aExpClipXHTML	Export to clipboard as XHTML
aExport	Export dialog
aFilesSearch	Search / Replace in Files dialog
aFind	Find dialog
aFindNext	Find Next
aFindPrev	Find Previous
aFindPrevWord	Previous Occurrence of Current Word
aFindWord	Next Occurrence of Current Word
aFont	Font dialog
aFullScreen	Full Screen mode
aGoogleSearch	Google Search dialog
aGotoLine	Goto Line dialog
aGUID	Insert GUID
aHexToDec	Hexadecimal to Decimal selection
aHTMLCompress	Compress HTML code
aHtmlCheck	Check HTML code
aHTMLPrev	HTML Page Preview
aHTMLReformat	Reformat HTML code
aHTMLSelTag	Select TAG
aIndent	Indent Block
aInfo	File Info
aInserFile	Insert From File...
aInsertText	Insert Text into Lines...
aInvertCase	Invert Case
aJoinLine	Join Lines
aLangHelp	Help for Language
aLastUserConvertor	Run Last used convertor
aLineNum	Line Numbers
aLogWindow	Show / Hide LOG window
aLoremIpsum	Lorem Ipsum generator
aLowerCase	To Lower Case
aMacroMgr	Macro Manager
aMacroPlay	Play Macro
aMacroRecord	Start / Stop Recording
aMailContents	As e-mail Contents
aMailFile	As e-mail Attachment
aMarkDown	Next Bookmark
aMarkList	Bookmark List
aMarkUp	Previous Bookmark
aMatchBracket	Matching Bracket
aMD5Gen	Hash generator dialog
aMoveAs	Move as dialog
aNew	New file dialog
aOpen	Open file dialog
aOpenCopy	Open Active File with New Name dialog
aOpenHex	Open in HEX Editor dialog
aOpenSame	Open R/O copy of Active File
aOpenSelected	Open file appointed by selection
aOpenWWWFile	Open File from Internet dialog
aPageSetup	Page Setup dialog
aPaste	Paste
aPasteHTML	Paste as HTML
aPasteNoMove	Paste Without Cursor Change
aPrint	Print file
aPrintPrev	Print Preview
aPrintSetup	Printer Settings dialog
aProjAddOpen	Add all open files to project
aProjFolderClose	Close files of current project folder
aProjFolderOpen	Open files of current prject folder
aProjFromDir	Create Project from Directory dialog
aProjInfo	Project Information dialog
aProjMainFile	Set File as Main for Compiler
aProjNew	New Project (closes all)
aProjOpen	Open Project dialog
aProjSave	Save Project
aProjSaveas	Save Project as dialog
aProjSettings	Project Settings dialog
aProjShow	Show/hide left Panel
aReadOnly	Read Only on/off for file
aRedo	Redo
aReformat	Reformat block (paragraph=blank line)
aReformat2	Reformat block (paragraph=short line)
aRemoveBlankLines	Remove Blank Lines
aRemoveFile	Remove File from Project
aRemoveRedundantBlank	Remove Redundant Blank Lines
aRemoveSpaces	Remove Redundant Spaces dialog
aRemoveTags	Remove HTML tags - it opens result in new window
aReOpen	Reopen Active File
aRepeatLastAction	Repeat last command
aReplace	Replace dialog
aRollBar	Ruler on/off
aRTFImport	Import text from RTF
aSave	Save current file
aSaveAll	Save All files
aSaveAs	Save As dialog
aSaveBlock	Save Block As dialog
aSaveSameTime	Save Without changing File Date
aSaveToFTP	Save to FTP
aSelectAll	Select All
aSelectNext	Next Window
aSelectPrew	Previous Window
aSelMatchBracket	Select Inside Brackets
aSelString	Select String
aSendToDisk	Save to Drive A:
aSentensize	Sentensize selection
aSetMain	Set as Main File for Compiler
aSetMark	Set Bookmark
aShellOpen	Open with associated application
aShowControlBar	Show/hide all toolbars
aShowSpecChar	Show/hide nonprinted characters
aSort	Sort dialog
aSpell	Online Spell Check on/off
aSpellCheck	Spell Check with dialog
aSpellSett	Spell Settings dialog
aStayOnTop	Stay on Top on/off
aSwapLineAbove	Swap line with line above (applicable to block)
aSwapLineBellow	Swap line with line bellow (applicable to block)
aSwitchLog	Jump to Editor / LOG
aSyntax	Syntax on/off
aSyntaxChange	Change Syntax dialog
aSysEdit	Open System Files (Autoexc, Config, ...)
aTabToSpaces	Convert Tabs to Spaces dialog
aTagToLowercase	Tags to Lowercase
aTagToUpperCase	Tags to Uppercase
aTextToHTML	Text to HTML
aToJScript	Selection to JavaScript
aToPHP	Selection to PHP variable
aUndo	Undo
aUnIndent	UnIndent Block
aUnQuote	Remove Email Quoting
aUpperCase	To Upper Case
aUserConvertors	User Convertors dialog
aWindCascade	Cascade windows
aWindSplitHoriz	Horizontal Split current file
aWindSplitVert	Vertical Split current file
aWindTile	Arrange windows
aWindTileHoriz	Tile windows Horizontal
aWindTileVert	Tile windows Vertical
aWordWrap	Word Wrap Lines on/off

sample vb script

' it will create new editor window, copy all text from first window into new
' and save new file as C:\SAMPLE.TXT
const module_name  = "sample"         'this name must be unique !!!
const module_desc  = "Sample script"  'script description
const module_ver   = "0.001a"         'version

sub Main                              'main procedure
  dim obj1, obj2, s                   'variable definition
  pspadVersion
  msgbox "PSPad version : " & pspadVersion()
  msgbox "Module version: " & moduleVersion("sample")
  set obj1 = getNewEditor()           'new editor object
  set obj2 = getNewEditor()           'new editor object
  obj2.assignEditorByIndex(0)         'assign PSPad window 1 to obj2
  obj1.NewFile()                      'opens new file in PSPad and assign to obj2
  s = obj2.getText                    'returns all text from window 1
  obj1.settext(s)                     'replaces all text in new window
  ' here is presented access to editor lines line by line
  dim item
  for each item in obj1
    MsgBox item
  next
  obj1.saveFileAs("C:\sample.txt")     'save as new editor
  obj1.closeFile                       'close copy file
end sub

sub Demo1
  msgbox "You run Demo1 from sample script"
end sub

sub Demo2
  msgbox "You run Demo2 from sample script"
end sub

' name "Init" is required, its called automatically during initialization to create menu items
sub Init
  addMenuItem "Main from Sample", "", "Main"
  addMenuItem "Demo1 from Sample","Sample - submenu", "Demo1" 
  addMenuItem "Demo2 from Sample","Sample - submenu", "Demo2" 
end sub

sample n.2 - run user convertor to all open files

const module_name  = "RunAction"         'this name must be unique !!!
const module_ver   = "0.001"             'version

sub Procedure
  set obj = NewEditor()
  for i = 0 to editorsCount - 1
      obj.assignEditorByIndex(i)
      obj.activate
      if i = 0 then  'for first file we call user convertor selector
         runPSPadAction "aUserConvertors"
      else           'for all other files we run last used convertor
         runPSPadAction "aLastUserConvertor"
      end if
  next  
end sub

' name "Init" is required, its called automatically during initialization to create menu items
sub Init
  addMenuItem "Run action demo (convert all open files)","", "Procedure"
end sub